//
//  UIBarButtonItem+extension.swift
//  MQWeibo
//
//  Created by 毛强 on 15/12/27.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
     convenience init(imageName:String? = nil, title:String? = nil, target:AnyObject?, action:Selector) {
    
        self.init()
        let button = UIButton()
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if imageName != nil {
            button.setImage(UIImage(named: imageName!), forState: .Normal)
            button.setImage(UIImage(named: "\(imageName!)_highlighted"), forState: .Highlighted)
        }
        
        if title != nil {
            button.setTitle(title, forState: .Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(15)
            button.setTitleColor(UIColor(white: 80/255, alpha: 1), forState: .Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        }
        
        button.sizeToFit()
        customView = button
        
    }
}
